﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using Xiaov.SmartWeb.Application.SupCan;

namespace Xiaov.SmartWeb.Application.StatisticsReport
{
    public partial class SCZSData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string bbbm = "SC15";
                if (Request.QueryString["bbbm"] != null)
                    bbbm = Request.QueryString["bbbm"].ToString().ToUpper();

                string nf = Request.QueryString["nf"];
                string yf = Request.QueryString["yf"];
                string dwbm = Request.QueryString["dwbm"];
                StringBuilder sbSql = new StringBuilder();
                string tempString = "";
                string dataString = ConfigurationManager.AppSettings[bbbm + "_Column"];   
                if (bbbm == "ZJYB_ZJYB00")
                {
                    sbSql.AppendFormat("select {0} from {1} zjyb_zjyb00", dataString, bbbm);
                }
                else if (bbbm == "SC15" || bbbm == "SC16" || bbbm == "SC17")
                {
                    tempString = "jh,chang,dui,zhan,dqmc,qkmc,cxmc,cyjh,tcrq,sczt,jb,bz";
                    sbSql.AppendFormat(@"select t.jh,a1.dwmc chang,a2.dwmc dui,a3.dwmc zhan,d.dqmc,b.qkmc,c.cxmc,t.cyjh,t.tcrq,t.sczt,t.jb,t.bz,
                        {0} from djjcxx t,{1} a,(select dwbm, dwmc from dwbmb where length(dwbm)=4) a1,(select dwbm, dwmc from dwbmb where length(dwbm)=6) a2,
                        (select dwbm, dwmc from dwbmb where length(dwbm)=8) a3,bm_qk b,bm_cx c,bm_dq d where a.jh=t.jh and a.nf={2} and a.yf={3}", dataString, bbbm, nf, yf);
                    if (dwbm == "HB")
                    {
                        sbSql.AppendFormat(" and a1.dwbm like '{0}%'", dwbm);
                    }
                    else
                    {
                        sbSql.AppendFormat(" and a1.dwbm='{0}'", dwbm);
                    }
                    sbSql.AppendFormat(@" and substr(t.dwbm, 1, 4) = a1.dwbm(+) and substr(t.dwbm, 1, 6) = a2.dwbm(+) 
                        and substr(t.dwbm, 1, 8) = a3.dwbm(+) and t.qkbm = b.qkbm(+) and t.cxbm = c.cxbm(+) and t.dqbm = d.dqbm(+)");
                }               
                DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(sbSql.ToString());              
                if (tempString != "")
                {
                    dataString += ",";
                    dataString += tempString;
                }
                ConvertToXml.Convert(ds.Tables[0], dataString, 0, ds.Tables[0].Rows.Count); 
            }
        }
    }
}